package com.xuhai.movie.controller;

import com.xuhai.movie.bean.Director;
import com.xuhai.movie.service.DirectorService;
import com.xuhai.movie.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author PangJunjie
 * @Date 2022/4/12/012
 */
@RestController
@RequestMapping("/director")
public class DirectorController {

    @Autowired
    private DirectorService directorService;

    @GetMapping("/page")
    public ResultJson page(int page, int limit, Director director){
        return directorService.getPage(page, limit, director);
    }

    @GetMapping("/info/{directorId}")
    public ResultJson info(@PathVariable Integer directorId){
        return directorService.getById(directorId);
    }

    @GetMapping("/select")
    public ResultJson select(){
        return directorService.getSelect();
    }

    @PostMapping(value = {"/update","/status"})
    public ResultJson update(@RequestBody Director director){
        directorService.saveOrUpdate(director);
        return ResultJson.ok();
    }

    @DeleteMapping("/delete/{directorId}")
    public ResultJson delete(@PathVariable Integer directorId){
        directorService.deleteById(directorId);
        return ResultJson.ok();
    }
}
